/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package drt;

import java.util.Iterator;
import java.util.LinkedHashSet;

/**
 *
 * @author phong
 */
public abstract class DrtStandAloneExpression implements DrtExpression {
    
    public DrtStandAloneExpression alphaConvert(LinkedHashSet<DrtVariable> vars) {
        try {
            LinkedHashSet<DrtVariable> thisVars = new LinkedHashSet<DrtVariable>();
            this.getAllVariables(thisVars);

            Iterator<DrtVariable> thisVarItor = thisVars.iterator();
            Iterator<DrtVariable> varItor = vars.iterator();
            DrtStandAloneExpression rep = this;

            while (thisVarItor.hasNext() && varItor.hasNext()) {
                rep = (DrtStandAloneExpression)rep.replace(thisVarItor.next(), varItor.next());
            }        

            return rep;
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        catch (Error e) {
            e.printStackTrace();
            return null;
        }
    }
}
